﻿namespace AnyOffice.DAL
{
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class FlowRunDao
    {
        public DataTable SelectByRunId(SqlConnection conn, int runId)
        {
            string commandText = "SELECT *,SUBSTRING([SignData],1,10) AS SignData2 FROM [dbo].[Flow_Run] WHERE [RunId] = @RunId ";
            SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@RunId", SqlDbType.Int) };
            commandParameters[0].Value = runId;
            DataSet set = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText, commandParameters);
            set.Tables[0].TableName = "Flow_Run";
            return set.Tables[0];
        }

        public bool UpdateAttachmentId(SqlConnection conn, int runId, string attachmentId)
        {
            string commandText = "UPDATE [dbo].[Flow_Run] SET [AttachmentId] = @AttachmentId WHERE [RunId] = @RunId";
            SqlParameter[] commandParameters = new SqlParameter[2];
            commandParameters[0] = new SqlParameter("@RunId", SqlDbType.Int);
            commandParameters[0].Value = runId;
            commandParameters[1] = new SqlParameter("@AttachmentId", SqlDbType.NText);
            commandParameters[1].Value = attachmentId;
            SqlHelper.ExecuteNonQuery(conn, CommandType.Text, commandText, commandParameters);
            return true;
        }
    }
}

